<script type="text/javascript">
    $(document).ready(function() {


        function getStudent(id) {

		$("#form").html(ajax_load);
		 $.get("student/getStudent?id="+id,function(data,status){
                    alert("Data: " + data + "\nStatus: " + status);
                   });
	
            
            
            
        }
        
        function getFaculties(id) {
            alert("editar " + id);
        }
        
        function confirmStudentChange(id) {
            alert("editar " + id);
        }
        
        function eraseStudent(id) {
            alert("eliminar " + id);
        }
        
        function showStudentForm(id) {
            alert("eliminar " + id);
        }

        // $("#edit_2").click(function(){
        $(":button").click(function() {
            var id = this.id;
            var action = id.slice(0, id.indexOf("_"));
            if (action === "edit") {
                getStudent(this.id);
            } else if (action === "erase") {
                eraseStudent(this.id);
            } else {
                alert("crear " + this.id);
            }
        });



    });
</script>    

<h1>Students List</h1>

<div id="form"></div>

<table>
    <thead>
        <tr>
            <th>Id</th>
            <th>Name</th>
            <th>Faculty</th>
            <th>Acciones</th>
        </tr>
    </thead>
    <tbody>
        <?php foreach ($students as $student): ?>
            <tr>
                <td><a href="<?php echo url_for('student/show?id=' . $student->getId()) ?>"><?php echo $student->getId() ?></a></td>
                <td><?php echo $student->getName() ?></td>
                <td><?php echo $student->getFaculty()->getName() ?></td>
                <td><input type="button" value="Editar" id="edit_<?php echo $student->getId() ?>"><input type="button" value="Eliminar" id="erase_<?php echo $student->getId() ?>"></input><a href="<?php echo url_for('student/show?id=' . $student->getId()) ?>">EditarBeta</a><a href="<?php echo url_for('student/show?id=' . $student->getId()) ?>">Editar</a><a href="<?php echo url_for('student/show?id=' . $student->getId()) ?>">Eliminar</a></td>
            </tr>
        <?php endforeach; ?>
    </tbody>
</table>

<input type="button" value="Crear" id="create"><a href="<?php echo url_for('student/new') ?>">New</a>




<br>
<?php //echo $JSONstudents ?>
<br>
<?php echo $JSONstudents;
?>
<br>
<?php echo $JSONfaculties;
?>

